package com.ruoyi.web.controller.decision;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.decision.domain.Model;
import com.ruoyi.decision.domain.StrategyConfigure;
import com.ruoyi.decision.service.IModelService;
import com.ruoyi.decision.service.IStrategyConfigureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 优化策略模型配置Controller
 * 
 * @author zbw
 * @date 2022-07-20
 */
@RestController
@RequestMapping("/decision/strategyconfigure")
public class StrategyConfigureController extends BaseController
{
    @Autowired
    private IStrategyConfigureService strategyConfigureService;

    @Autowired
    private IModelService modelService;

    /**
     * 查询优化策略模型配置列表中的策略id
     */
    @PreAuthorize("@ss.hasPermi('decision:strategyconfigure:strategyId')")
    @GetMapping("/strategyId/{strategyId}")
    public TableDataInfo cs(@PathVariable("strategyId")String strategyId)
    {
       startPage();
       List<StrategyConfigure> list = strategyConfigureService.selectStrategyConfigureByStrategyId(strategyId);
        List<Model> models = modelService.selectSPlmRtsModelList(null);
        List<Model> models1 = new ArrayList<>();
        for (Model model : models) {
            for (StrategyConfigure strategyConfigure : list) {
                if (model.getModelId().equals(strategyConfigure.getModelId())){
                    models1.add(model);
                }
            }
        }
       return getDataTable(models1);

    }

    /**
     * 查询优化策略模型配置列表
     */
    @PreAuthorize("@ss.hasPermi('decision:strategyconfigure:list')")
    @GetMapping("/list")
    public TableDataInfo list(StrategyConfigure strategyConfigure)
    {
        startPage();
        List<StrategyConfigure> list = strategyConfigureService.selectStrategyConfigureList(strategyConfigure);
        return getDataTable(list);
    }

    /**
     * 导出优化策略模型配置列表
     */
    @PreAuthorize("@ss.hasPermi('decision:strategyconfigure:export')")
    @Log(title = "优化策略模型配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StrategyConfigure strategyConfigure)
    {
        List<StrategyConfigure> list = strategyConfigureService.selectStrategyConfigureList(strategyConfigure);
        ExcelUtil<StrategyConfigure> util = new ExcelUtil<StrategyConfigure>(StrategyConfigure.class);
        util.exportExcel(response, list, "优化策略模型配置数据");
    }

    /**
     * 获取优化策略模型配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('decision:strategyconfigure:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(strategyConfigureService.selectStrategyConfigureById(id));
    }

    /**
     * 新增优化策略模型配置
     */
    @PreAuthorize("@ss.hasPermi('decision:strategyconfigure:add')")
    @Log(title = "优化策略模型配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StrategyConfigure strategyConfigure)
    {

        return toAjax(strategyConfigureService.insertStrategyConfigure(strategyConfigure));
    }

    /**
     * 修改优化策略模型配置
     */
    @PreAuthorize("@ss.hasPermi('decision:strategyconfigure:edit')")
    @Log(title = "优化策略模型配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StrategyConfigure strategyConfigure)
    {
        return toAjax(strategyConfigureService.updateStrategyConfigure(strategyConfigure));
    }

    /**
     * 删除优化策略模型配置
     */
    @PreAuthorize("@ss.hasPermi('decision:strategyconfigure:remove')")
    @Log(title = "优化策略模型配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(strategyConfigureService.deleteStrategyConfigureByIds(ids));
    }
}
